<template>
  <div class="operating">
    <div class="title">操作记录</div>
    <div class="top">
      <div class="d-flex">
        <el-form label-width="120px" class="d-flex">
          <el-form-item label="操作人:">
            <el-select v-model="value" placeholder="请选择" @change="checkOperate">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="操作日期:">
            <el-date-picker
              v-model="value1"
              type="daterange"
              value-format="yyyy-MM-dd"
              @change="datePickChange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </el-form-item>
          <el-form-item label="操作内容:">
            <el-input placeholder="请输入买家昵称" v-model="form.name"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <el-button class="add" @click="updateTable">筛选</el-button>
    </div>
    <div class="table">
      <el-table :data="tableData" :height="height" style="width: 100%">
        <el-table-column prop="account" label="操作人" width="180" />
        <el-table-column prop="content" label="操作内容"  />
        <el-table-column prop="created_at" label="操作时间" width="180"/>
        <el-table-column prop="ip" label="操作IP" />
      </el-table>
    </div>
    <Pagination class="pagination" :total="total" @nextPage="handleNextPage" />
  </div>
</template>
<script>
import Input from "@/common/input";
import Pagination from "@/common/pagination";
import Resize from '@/common/mixins/resize'
import { getOperateList, getOperator } from "@/api/http/designer";

export default {
  components: {
    Input,
    Pagination,
  },
  mixins: [Resize],
  data() {
    return {
      defaultHeight:280,
      value1: "",
      total: 0,
      page: 1,
      form: {},
      options: [],
      value: "",
      query: "",
      tableData: []
    };
  },
  created() {
    this.getOperator();
    this.getOperateList();
  },
  methods: {
    handleNextPage(page) {
      this.page = page;
      this.getOperateList();
    },
    // 获取操作人数据
    getOperator() {
      getOperator().then(res => {
        // console.log(res, "---res---操作人");
        if (res.code == 200) {
          var arr = res.data.list;
          arr.map((res, i) => {
            this.options.push({
              value:res.id,
              label:res.account
            });
          });
        }
      });
    },
    // 筛选操作人
    updateTable(){
      this.getOperateList();
    },
    checkOperate(){},
    // 获取操作记录数据
    getOperateList() {
      getOperateList({
        page: this.page,
        keywords: this.form.name,
        start_at: this.form.start_at,
        end_at: this.form.end_at,
        operation_id:this.value
      }).then(res => {
        // console.log(res, "---res");
        if (res.code == 200) {
          this.total = res.data.total;
          this.tableData = res.data.data;
        }
      });
    },
    datePickChange(val) {
      if (val) {
        this.form.start_at = val[0];
        this.form.end_at = val[1];
      } else {
        this.form.start_at = "";
        this.form.end_at = "";
      }
    },
  }
};
</script>
<style lang="scss" scoped>
@import "@/styles/el-button.scss";
@import "@/styles/el-pagination.scss";
@import "@/styles/el-table.scss";
.title {
  line-height: 40px;
  color: rgba(16, 16, 16, 1);
  font-size: 18px;
  text-align: left;
  font-weight: bold;
  font-family: Roboto;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .el-form-item {
    margin: 0;
  }
}
.table {
  margin-top: 20px;
}
.d-flex {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
</style>
